//
//  ECNavigationController.m
//  ERPChargeAccount2
//
//  Created by huanggulong on 2018/6/9.
//  Copyright © 2018年 历山大亚. All rights reserved.
//

#import "ECNavigationController.h"

@interface ECNavigationController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>

@end

@implementation ECNavigationController

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController{
    self = [super initWithRootViewController:rootViewController];
    if (self) {
        
    }
    return self;
}

+ (void)initialize{
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    [navigationBar setBackgroundImage:[UIImage gl_imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
    navigationBar.shadowImage = [UIImage gl_imageWithColor:[UIColor whiteColor]];
    navigationBar.tintColor = @"#FFFFFF".toColor;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    if (self.navigationController.viewControllers.count == 1) {
        return NO;
    }else{
        return YES;
    }
}

#pragma mark - override
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0) {
        //防止重复push同一个view controller引发crash
        if ([self.viewControllers containsObject:viewController]) {
            return;
        }
        self.interactivePopGestureRecognizer.delegate = self;
    }else{
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    if ( self.viewControllers.count == 0) {
        viewController.hidesBottomBarWhenPushed = NO;
    }else {
        /* v3.0 显示底部导航tab */
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    /*  调用父类的方法  */
    [super pushViewController:viewController animated:animated];
    
}



- (BOOL)shouldAutorotate{
    return self.topViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return self.topViewController.supportedInterfaceOrientations;
}

@end
